function trim(str){
    return str.replace(/(^\s*)|(\s*$)/g,"");
  }//去掉空格
function chekedinfo(){
        var ch_name =document.getElementById('ch_name') .value;
		var out_link =document.getElementById('out_link') .value;
        if (trim(ch_name) == ''){
			 	alert("栏目名称不能为空!"); 
				document.getElementById('ch_name').focus();
				return false;
			}
	var strRegex = "^((https|http|ftp|rtsp|mms)?://)"
						+ "?(([0-9a-z_!~*'().&=+$%-]+: )?[0-9a-z_!~*'().&=+$%-]+@)?" // ftp的user@
						+ "(([0-9]{1,3}\.){3}[0-9]{1,3}" // IP形式的URL- 199.194.52.184
						+ "|" // 允许IP和DOMAIN（域名）
						+ "([0-9a-z_!~*'()-]+\.)*" // 域名- www.
						+ "([0-9a-z][0-9a-z-]{0,61})?[0-9a-z]\." // 二级域名
						+ "[a-z]{2,6})" // first level domain- .com or .museum
						+ "(:[0-9]{1,4})?" // 端口- :80
						+ "((/?)|" // a slash isn't required if there is no file name
						+ "(/[0-9a-z_!~*'().;?:@&=+$,%#-]+)+/?)$";
	var re = new RegExp(strRegex);
	if (trim(out_link)!=''&&!re.test(out_link))
	{
	
	alert("外部链接地址的格式不正确!");
	document.getElementById('out_link').focus();
	return false;
  }
document.addForm.submit();
}
function choiceFile(cur_page,ch_id){
	var gURL = "filelist.jsp?id=index_temp&height=400&width=750&file_path=&cur_page="+cur_page+"&ch_id="+ch_id;
	TB_show("文件选择页",gURL,true);
}

function setIndexTemp(cur_page,val,ch_id){
	if(val==""){
		alert("模板不能为空");
		return false;
	}
	if(cur_page=="add")
		document.location.href="/program/admin/channel/addInfo.jsp?index_temp="+val;
	else if(cur_page=="update")
		document.location.href="/program/admin/channel/updateInfo.jsp?index_temp="+val+'&ch_id='+ch_id;
	TB_remove();
}

function pp(vg){
	if(vg!=""){
		var str=/^[A-Za-z\/]+$/;
			if(str.test(vg)){				
				return true;
			}else{
				alert('格式不正确');
				document.getElementById('save_dir').focus();
				return false;
			}
	}	
}


function selectAll(){
	var checkall = document.getElementById('checkall');
	var listsize = document.getElementById('listsize').value;
	for(var i=0;i<listsize;i++){
		if(checkall.checked){
			document.getElementById('checkone'+i).checked = true;
		}else{
			document.getElementById('checkone'+i).checked = false;
		}
	}
}

function delIndexInfo(){
	var listsize = document.getElementById('listsize').value;
	var ifdown ='';
	var ifnews='';
	var pkid_string = '';
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
			pkid_string += document.getElementById('checkone'+i).value+'|';
		}
	}
	
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
		 if(document.getElementById('hasDown'+i).value=='1'){					 
			  ifdown=1;
			  break;
			}
		}
	} 
	
	for(var i=0;i<listsize;i++){
		if(document.getElementById('checkone'+i).checked){
		 if(document.getElementById('ckecknews'+i).value=='1'){					 
			  ifnews=1;
			  break;
			}
		}
	} 
	if(pkid_string == ''){
		alert('请至少选择一条!');
		return false;
	}
	else{
	document.getElementById('pkid').value = pkid_string;
	document.indexForm.action='/doTradeReg.do';
	if(ifdown =='1'){          
		       //if(window.confirm( '所选择含有下级栏目，请先删除下级')){
				   alert('所选择含有下级栏目，请先删除下级');
			   	     return false;
		       //} 
	      }
		  else if(ifnews =='1'){    	  
		       if(window.confirm( '所选择栏目下含有资讯，请先删除资讯')){				    
			   	     return false;
		       } 
	      }
	else if(window.confirm('确定要删除吗？')){
		document.indexForm.submit();
		
	}
 }
}


function searchForm(){
	
	 document.indexForm .submit();
	
}

function delOneNews(val1,val2,sel){
	
	  var ifdown= document.getElementById('hasDown'+val1).value;
	  var ifnews= document.getElementById('ckecknews'+sel).value;
		
		if(ifdown=='1')
		{
			//if(window.confirm("该栏目含有下级，请先删除下级")){
			alert("该栏目含有下级，请先删除下级");
		     return ;
	    //}		
	  }	
	  else if(ifnews !=null&&ifnews =='1'){    	  
		       if(window.confirm( '所选择栏目下含有资讯，请先删除资讯')){				    
			   	     return false;
		       } 
	      }
		else	 
		
        if(window.confirm('确定要删除吗?'))
        {
       	  window.location.href='/doTradeReg.do?pkid='+val2+'&bpm_id=3449'; 
        } 		
    
	
}

function checkChannelName(){
	var ch_name = document.getElementById('ch_name').value;
	var bool = true;
	jQuery.ajax({
		type: "POST",
		url: "checkChannelName.jsp",
		data:"ch_name=" + ch_name,
		success: function(data){
			 if(data!=null && trim(data)!=""){
				if( data == 1 ){
					alert('该名称已存在，请重新命名！');
					document.getElementById('ch_name').value = '';
					document.getElementById('ch_name').focus();
					bool = false;
				}
			 }
		}
	});
	return bool;
}

 



